package com.mydemo.utils.base;

import java.io.IOException;

public class FfmpegConverter {
    public static void main(String[] args) {
        String mp44FilePath = "D:\\mp4totext\\古籍修复.mp4";
        String wavFilePath = "D:\\mp4totext\\古籍修复.wav";
        // 构建命令
        ProcessBuilder pb = new ProcessBuilder(
                "ffmpeg",
                "-i", mp44FilePath,
                "-ar", "16000",
                "-ac", "1",
                "-acodec", "pcm_s16le",
                wavFilePath
        );

        try {
            // 启动进程并等待完成
            Process process = pb.start();
            int exitCode = process.waitFor();
            if (exitCode == 0) {
                System.out.println("转换成功！");
            } else {
                System.out.println("转换失败，错误码：" + exitCode);
            }
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}
